home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5785 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  47 lines

  1. Path: usenet.cis.ufl.edu!caen!hasdi
  2. From: hasdi@news-server.engin.umich.edu (HASDI RODZMANN HASHIM)
  3. Newsgroups: comp.lang.c
  4. Subject: Do you have ever pass structures?
  5. Date: 21 Feb 1996 04:56:50 GMT
  6. Organization: University of Michigan Engineering, Ann Arbor
  7. Message-ID: <4ge8mi$qjm@srvr1.engin.umich.edu>
  8. NNTP-Posting-Host: hasdi@date.engin.umich.edu
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. As I gain more and more experience in writing C code (sure), I find
  12. myself passing more and more information and returning even more.
  13. This is where using structures become handy.
  14.  
  15. MY QUESTION is do you ever pass the whole structures to a function
  16. or you just pass a pointer to a function? For example, for a struct
  17. of the following size...
  18.  
  19. struct _bar {
  20.     int    a;
  21.     int    b;
  22.     float    c;
  23.     double    d;
  24.     char    e[100];
  25. }
  26.  
  27. typedef _bar bar;
  28.  
  29. I find myself writing...
  30.     void    foo(bar *a)
  31. instead of 
  32.     void    foo(bar)
  33.  
  34. If I want to avoid bar from being modified, one limited way to do
  35. it is to add the CONST qualifier.
  36.     void    foo(const bar *a)
  37.  
  38. So is there any REAL advantage is passing an entire structure? Do people
  39. ever do it? I've some people's source code and almost always, they
  40. pass pointers to structures instead of the structure itself. In a way,
  41. passing a pointer to an array instead of the array itself might be
  42. feature not a bug in C. :)
  43.  
  44. Thank you!
  45.  
  46. Hasdi
  47.